$(".head_123").load("http://localhost:3000/public/public.html .heade_1",()=>{



// ===搜索栏api===
const otxt = document.getElementById("txt");
const olist = document.getElementById("list"); //list由js生成
const url = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su";
const osearch = document.querySelector(".search");
const ologin = document.querySelector(".login");
const owelcome = document.querySelector(".welcome");
const oun = document.querySelector(".un");
const oexit = document.querySelector(".exit");
// 搜索栏输入时获取
otxt.addEventListener("input", function() {
    olist.style.display = "block";
    // 3没有内容 下拉栏也为空
    if (this.value === "") {
        olist.innerHTML = "";
        return; //以下程序不执行
    }
  
    // 1拼接数据：关键字+函数名 this.value拿到文本框内容
    const str = `wd=${this.value}&cb=xixi`;
    // 创建script标签 将数据拼到url 准备jsonp
    const script = document.createElement("script");
    script.src = url + "?" + str;
    document.body.appendChild(script);

    // 2绑定全局变量 能在外面拿到这个函数
    window.xixi = function(res) {
        // 创建li 接口规定：res.s拿到要的联想搜索
        let str = "";
        for (let i = 0; i < res.s.length; i++) {
            str += `<li>${res.s[i]}</li>`
        }
        // 放到olist里
        olist.innerHTML = str;
    }

    olist.addEventListener("click", function(eve) {

        let e = eve || window.event;
        let target = e.target || e.srcElement;
        // console.log(target);

        olist.style.display = "none";
        // 把内容设置给搜索框
        otxt.value = target.innerText;

    })
    osearch.addEventListener("click", function() {
        otxt.value = "";
        location.href = "./goodslist.html"

    })
})
 //二级菜单
 
 $(function(){
    $("ul").find("li").hover(function(){
        $(this).children("ul").show();
    },function(){
        $(this).children("ul").hide();
    })
}) 
//退出功能
// 判断是否登录
if (localStorage.getItem("isLogin") === "ok") {
    ologin.style.display = "none";
    owelcome.style.display = "block";
    oun.innerHTML = localStorage.getItem("username");
} else {
    ologin.style.display = "block";
    owelcome.style.display = "none";
    oun.innerHTML = "xxx";
}
// 点击退出
oexit.onclick = function() {
        localStorage.removeItem("username");
        localStorage.setItem("isLogin", "");
        ologin.style.display = "block";
        owelcome.style.display = "none";
        oun.innerHTML = "xxx";
    }



const ocart=document.querySelector(".cart")
const omy = document.querySelector(".my")
//===================================
//// 守卫登录1 页面不允许跳转购物车
ocart.onclick = function() {
    if (localStorage.getItem("isLogin") === "ok") {
        location.href = "./cart.html"
    } else {
        alert("未登录状态，不允许打开购物车，请先登录")
        location.href = "./login.html"
    }
}

omy.onclick = function() {
    if (localStorage.getItem("isLogin") === "ok") {
        location.href = "./personal.html"
    } else {
        alert("未登录状态，不允许打开个人中心，请先登录")
        location.href = "./login.html"
    }
}

// 守卫2：页面守卫 不允许通过网址进入购物车
if (localStorage.getItem("isLogin") !== "ok") {
    alert("未登录状态，不允许打开，请先登录")
    location.href = "./login.html";
}


//=====================================


})
$(".ylk111").load("http://localhost:3000/public/public.html .ylk")
$(".bottoms1").load("http://localhost:3000/public/public.html .bottoms")
$(".foot").load("http://localhost:3000/public/public.html .footer-box")





